﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

using SafoverWpfFw;
using System.Net;
using System.Windows.Input;
using Safover.LidarCollector.Models;
using Safover.LidarCollector.Config;

namespace Safover.LidarCollector.ViewModel
{
    public class AcquisitionCardConfigViewModel : BaseViewModel
    {
        public ICommand SaveCommand { get; set; }

        public int Port { get; set; }
        public IPAddress ClientIP { get; set; }
        public IPAddress HostIP { get; set; }
        
        public string Channel1Name { get; set; }
        public string Channel2Name { get; set; }
        public string Channel3Name { get; set; }
        public string Channel4Name { get; set; }

        /// <summary>
        /// 空间分辨率；空间解析度
        /// </summary>
        public double SpatialResolution { get; set; }
        public int SamplingDepth { get; set; }
        public int CumulativePulses { get; set; }

        public AcquisitionCardConfigViewModel(AcquisitionCardConfig config)
        {
            Port = config.Port;
            ClientIP = config.ClientIP;
            HostIP = config.HostIP;

            Channel1Name = config.Channel1Name;
            Channel2Name = config.Channel2Name;
            Channel3Name = config.Channel3Name;
            Channel4Name = config.Channel4Name;

            SpatialResolution = config.SpatialResolution;
            SamplingDepth = config.SamplingDepth;
            CumulativePulses = config.CumulativePulses;

            SaveCommand = new RelayCommand(Save);
        }

        private void Save()
        {
            var config = new AcquisitionCardConfig
            {
                Port = Port,
                ClientIP = ClientIP,
                HostIP = HostIP,
                
                Channel1Name = Channel1Name,
                Channel2Name = Channel2Name,
                Channel3Name = Channel3Name,
                Channel4Name = Channel4Name,

                SpatialResolution = SpatialResolution,
                SamplingDepth = SamplingDepth,
                CumulativePulses = CumulativePulses,
            };

            RuntimeConfigManager.Instance.Save(config);

            _ = DI.UI.ShowMessage(new MessageBoxDialogViewModel
            {
                Title = "提示",
                Message = "保存成功！"
            });
        }
    }
}
